home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / TEST_AS1.C < prev    next >
C/C++ Source or Header  |  1992-09-23  |  8KB  |  219 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/String.h>
  14. #include <cool/Association.h>
  15. #include <test.h>
  16.  
  17. #include <cool/Pair.C>
  18. #include <cool/Vector.C>
  19. #include <cool/Association.C>
  20.  
  21. Boolean my_compare_charP (char* const& s1, char* const& s2) {
  22.   return (strcmp (s1, s2) ? FALSE : TRUE);
  23. }
  24.  
  25. void xx(CoolPair<int,char*>); //##
  26.  
  27. void test_int_charP () {
  28.   int key;
  29.   char* value;
  30.  
  31.   CoolAssociation<int,char*> a0;
  32.   TEST("CoolAssociation<int,char*> a0", 1, 1);
  33.   TEST ("a0.length()", a0.length(), 0);
  34.   TEST ("a0.capacity()", a0.capacity(), 0);
  35.   CoolAssociation<int,char*> a1(5);
  36.   TEST("CoolAssociation<int,char*> a1(5)", 1, 1);
  37.   TEST ("a1.length()", a1.length(), 0);
  38.   TEST ("a1.capacity()", a1.capacity(), 5);
  39.   a1.set_value_compare(&my_compare_charP);
  40.   TEST ("a1.set_value_compare(&my_compare_charP)",1,1);
  41.   CoolAssociation<int,char*> a2(10);
  42.   TEST ("CoolAssociation<int,char*> a2(10)",1,1);
  43.   TEST ("a2.capacity()",a2.capacity(),10);
  44.   TEST ("a2.put(1,\"AAA\")",a2.put(1,"AAA"), TRUE);
  45.   TEST ("a2.put(2,\"BBB\")",a2.put(2,"BBB"), TRUE);
  46.   TEST ("a2.put(3,\"CCC\")",a2.put(3,"CCC"), TRUE);
  47.   TEST ("a2.put(4,\"DDD\")",a2.put(4,"DDD"), TRUE);
  48.   TEST ("a2.length()", a2.length(), 4);
  49.   TEST ("a2.capacity()", a2.capacity(), 10);
  50.   CoolAssociation<int,char*> a3 = a2;
  51.   TEST("CoolAssociation<int,char*> a3 = a2", 1, 1);
  52.   TEST ("a3.length()", a3.length(), 4);
  53.   TEST ("a3.capacity()", a3.capacity(), 10);
  54.   TEST ("a2 == a3", a2 == a3, TRUE);
  55.   TEST("a3 != a1", (a3 != a1), TRUE);
  56.   TEST("a3 = a1", (a3 = a1), a1);
  57.   TEST("a2.find(3)", a2.find(3), TRUE);
  58.   TEST("a2.value()", (strcmp (a2.value(),"CCC")), 0);
  59.   TEST("a2.prev()", (a2.prev() && !strcmp(a2.value(),"BBB")), TRUE);
  60.   TEST("a2.key()", a2.key(), 2);
  61.   TEST("a2.next()", (a2.next() && !strcmp(a2.value(),"CCC")), TRUE);
  62.   TEST("a2.get(1, value)", (a2.get(1, value) && !strcmp(value,"AAA")), TRUE);
  63.   TEST("a2.get_key(\"DDD\", key)", (a2.get_key("DDD", key) && key==4), TRUE);
  64.   TEST("a2.length()", a2.length(), 4);
  65.   TEST("a2.put(5,\"EEE\")", (a2.put(5,"EEE") && a2.length() == 5), TRUE);
  66.   a2.reset();
  67.   TEST("a2.reset()", a2.prev(), TRUE);
  68.   TEST("a2.find(2)", a2.find(2), TRUE);
  69.   TEST("a2.remove()", strcmp (a2.remove(),"BBB"),0);
  70.   TEST("a2.remove(4)", a2.remove(4), TRUE);
  71.   TEST("a2.remove(4)", a2.remove(4), FALSE);
  72.   a1.resize(10);
  73.   TEST("a1.resize(10)", 1, 1);
  74.   a0.set_length(2);
  75.   TEST("a0.set_length(2)", 1, 1);
  76.   a3.set_growth_ratio(2.0);
  77.   TEST("a3.set_growth_ratio", 1, 1);
  78. }
  79.  
  80. void xx(CoolPair<int,double>); //##
  81.  
  82. void test_int_double () {
  83.   double a = 1.0;
  84.   double b = 2.0;
  85.   double c = 3.0;
  86.   double d = 4.0;
  87.   double e = 5.0;
  88.  
  89.   int key;
  90.   double value;
  91.  
  92.   CoolAssociation<int,double> a0;
  93.   TEST("CoolAssociation<int,double> a0", 1, 1);
  94.   TEST ("a0.length()", a0.length(), 0);
  95.   TEST ("a0.capacity()", a0.capacity(), 0);
  96.   CoolAssociation<int,double> a1(5);
  97.   TEST("CoolAssociation<int,double> a1(5)", 1, 1);
  98.   TEST ("a1.length()", a1.length(), 0);
  99.   TEST ("a1.capacity()", a1.capacity(), 5);
  100.   CoolAssociation<int,double> a2(10);
  101.   TEST ("CoolAssociation<int,double> a2(10)",1,1);
  102.   TEST ("a2.capacity()",a2.capacity(),10);
  103.   TEST ("a2.put(1,1.0)",a2.put(1,1.0), TRUE);
  104.   TEST ("a2.put(2,2.0)",a2.put(2,2.0), TRUE);
  105.   TEST ("a2.put(3,3.0)",a2.put(3,3.0), TRUE);
  106.   TEST ("a2.put(4,4.0)",a2.put(4,4.0), TRUE);
  107.   TEST ("a2.length()", a2.length(), 4);
  108.   TEST ("a2.capacity()", a2.capacity(), 10);
  109.   CoolAssociation<int,double> a3 = a2;
  110.   TEST("CoolAssociation<int,double> a3 = a2", 1, 1);
  111.   TEST ("a3.length()", a3.length(), 4);
  112.   TEST ("a3.capacity()", a3.capacity(), 10);
  113.   TEST ("a2 == a3", a2 == a3, TRUE);
  114.   TEST("a3 != a1", (a3 != a1), TRUE);
  115.   TEST("a3 = a1", (a3 = a1), a1);
  116.   TEST("a2.find(3)", a2.find(3), TRUE);
  117.   TEST("a2.value()", (a2.value() == c), TRUE);
  118.   TEST("a2.prev()", (a2.prev() && a2.value() == b), TRUE);
  119.   TEST("a2.key()", a2.key(), 2);
  120.   TEST("a2.next()", (a2.next() && a2.value() == c), TRUE);
  121.   TEST("a2.get(1, value)", (a2.get(1, value) && value==a), TRUE);
  122.   TEST("a2.get_key(d, key)", (a2.get_key(d, key) && key==4), TRUE);
  123.   TEST("a2.length()", a2.length(), 4);
  124.   TEST("a2.put(5,e)", (a2.put(5,e) && a2.length() == 5), TRUE);
  125.   a2.reset();
  126.   TEST("a2.reset()", a2.prev(), TRUE);
  127.   TEST("a2.find(2)", a2.find(2), TRUE);
  128.   TEST("a2.remove()", a2.remove(), b);
  129.   TEST("a2.remove(4)", a2.remove(4), TRUE);
  130.   a1.resize(10);
  131.   TEST("a1.resize(10)", 1, 1);
  132.   a0.set_length(2);
  133.   TEST("a0.set_length(2)", 1, 1);
  134.   a3.set_growth_ratio(2.0);
  135.   TEST("a3.set_growth_ratio", 1, 1);
  136. }
  137.  
  138. void xx(CoolPair<int,CoolString>); //##
  139.  
  140. void test_int_String () {
  141.   CoolString a = "AAA";
  142.   CoolString b = "BBB";
  143.   CoolString c = "CCC";
  144.   CoolString d = "DDD";
  145.   CoolString e = "EEE";
  146.  
  147.   int key;
  148.   CoolString value;
  149.  
  150.   CoolAssociation<int,CoolString> a0;
  151.   TEST("CoolAssociation<int,CoolString> a0", 1, 1);
  152.   TEST ("a0.length()", a0.length(), 0);
  153.   TEST ("a0.capacity()", a0.capacity(), 0);
  154.   CoolAssociation<int,CoolString> a1(5);
  155.   TEST("CoolAssociation<int,CoolString> a1(5)", 1, 1);
  156.   TEST ("a1.length()", a1.length(), 0);
  157.   TEST ("a1.capacity()", a1.capacity(), 5);
  158.   CoolAssociation<int,CoolString> a2(10);
  159.   TEST ("CoolAssociation<int,CoolString> a2(10)",1,1);
  160.   TEST ("a2.capacity()",a2.capacity(),10);
  161.   TEST ("a2.put(1,CoolString(\"AAA\"))",a2.put(1,CoolString("AAA")), TRUE);
  162.   TEST ("a2.put(2,CoolString(\"BBB\"))",a2.put(2,CoolString("BBB")), TRUE);
  163.   TEST ("a2.put(3,CoolString(\"CCC\"))",a2.put(3,CoolString("CCC")), TRUE);
  164.   TEST ("a2.put(4,CoolString(\"DDD\"))",a2.put(4,CoolString("DDD")), TRUE);
  165.   TEST ("a2.length()", a2.length(), 4);
  166.   TEST ("a2.capacity()", a2.capacity(), 10);
  167.   CoolAssociation<int,CoolString> a3 = a2;
  168.   TEST("CoolAssociation<int,CoolString> a3 = a2", 1, 1);
  169.   TEST ("a3.length()", a3.length(), 4);
  170.   TEST ("a3.capacity()", a3.capacity(), 10);
  171.   TEST ("a2 == a3", a2 == a3, TRUE);
  172.   TEST("a3 != a1", (a3 != a1), TRUE);
  173.   TEST("a3 = a1", (a3 = a1), a1);
  174.   TEST("a2.find(3)", a2.find(3), TRUE);
  175.   TEST("a2.value()", (a2.value() == c), TRUE);
  176.   TEST("a2.prev()", (a2.prev() && a2.value() == b), TRUE);
  177.   TEST("a2.key()", a2.key(), 2);
  178.   TEST("a2.next()", (a2.next() && a2.value() == c), TRUE);
  179.   TEST("a2.get(1, value)", (a2.get(1, value) && value==a), TRUE);
  180.   TEST("a2.get_key(d, key)", (a2.get_key(d, key) && key==4), TRUE);
  181.   TEST("a2.length()", a2.length(), 4);
  182.   TEST("a2.put(5,e)", (a2.put(5,e) && a2.length() == 5), TRUE);
  183.   a2.reset();
  184.   TEST("a2.reset()", a2.prev(), TRUE);
  185.   TEST("a2.find(2)", a2.find(2), TRUE);
  186.   TEST("a2.remove()", a2.remove(), b);
  187.   TEST("a2.remove(4)", a2.remove(4), TRUE);
  188.   a1.resize(10);
  189.   TEST("a1.resize(10)", 1, 1);
  190.   a0.set_length(2);
  191.   TEST("a0.set_length(2)", 1, 1);
  192.   a3.set_growth_ratio(2.0);
  193.   TEST("a3.set_growth_ratio", 1, 1);
  194.   cout << a2 << endl;
  195. }
  196.  
  197. void test_leak () {
  198.   for (;;) {
  199.     test_int_double ();
  200.     test_int_charP ();
  201.     test_int_String ();
  202.   }
  203. }
  204.  
  205. int main () {
  206.   START("CoolAssociation");
  207.   test_int_double ();
  208.   test_int_charP ();
  209.   test_int_String ();
  210. #if LEAK
  211.   test_leak ();
  212. #endif
  213.   SUMMARY();
  214.   return 0;
  215. }
  216.  
  217.  
  218.  
  219.